﻿using Platformer_Example.Content.Images.Player;
using Platformer_Example.Controller.Input;
using System;
using Transformable_Engine_v2.Engine.Animation.FrameAnimation;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Platformer_Example.Controller.Character.Player
{
    public partial class Player
    {
        private FrameAnimation _animation;

        protected override void CreateWalkStateObjects()
        {
        }

        protected override void InitializeWalkState()
        {
            if (IsCarryingObject)
            {
                Character.AddAnimations(_animation = new FrameAnimation(new PlayerAnimations.Normal.WalkCarry()));
                Character.OriginAbsolute = new TE_Vector2(8, 32);
                OnChangeWalkFrame(0);
            }
            else
            {
                Character.AddAnimations(_animation = new FrameAnimation(new PlayerAnimations.Normal.Walk()));
                Character.OriginAbsolute = new TE_Vector2(8, 32);
            }

            _animation.OnChangeFrame += OnChangeWalkFrame;
        }

        private void OnChangeWalkFrame(int frameid)
        {
            if (IsCarryingObject)
            {
                switch (frameid)
                {
                    case 0:
                    case 3:
                        CarriedObject.Position = new TE_Vector2(0, -21);
                        break;
                    case 1:
                    case 4:
                        CarriedObject.Position = new TE_Vector2(0, -22);
                        break;
                    case 2:
                    case 5:
                        CarriedObject.Position = new TE_Vector2(0, -23);
                        break;
                }
            }
        }

        protected override void UpdateWalkState(TimeSpan gameTime)
        {
        }

        protected override void EndWalkState()
        {
            Character.ClearAnimation<FrameAnimation>();
            _animation.OnChangeFrame -= OnChangeWalkFrame;
        }

        protected override TE_Vector2 MovementSpeed
        {
            get { return new TE_Vector2(0.45f, 0).ToGridbound(); }
        }

        protected override void OnKeyPressWalk(InputState.Key key)
        {
        }

        protected override void OnKeyReleaseWalk(InputState.Key key)
        {
        }
    }
}